Last Update: 2025/3/26
Qwen Speech API 【Deprecate】
The Qwen Speech API allows you to convert text to speech using OpenAI's SDK. This document provides an overview of the API endpoints, request parameters, and response structure.
Endpoint
POST https://platform.llmprovider.ai/v1/audio/speech
Request Headers
Header | Value |
---|---|
Authorization | Bearer YOUR_API_KEY |
Content-Type | application/json |
Request Body
The request body should be a JSON object with the following parameters:
Parameter | Type | Description |
---|---|---|
model | string | The model to use (e.g., qwen2-audio-instruct ). |
input | string | The text to generate audio for. The maximum length is 4096 characters. |
voice | string | The voice to use (alloy , echo , fable , onyx , nova , or shimmer ). |
response_format | string | (Optional) The format of the audio response (mp3 , opus , aac , or flac ). |
speed | number | (Optional) The speed of the generated audio. Select a value from 0.25 to 4.0. 1.0 is the default. |
Example Request
{
"model": "qwen2-audio-instruct",
"input": "Hello, how are you today?",
"voice": "alloy",
"response_format": "mp3",
"speed": 1.0
}
Response
The API returns an audio file in the requested format.
Example Request
- Shell
- nodejs
- python
curl -X POST https://platform.llmprovider.ai/v1/audio/speech \
-H "Authorization: Bearer $YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen2-audio-instruct",
"input": "Hello, how are you today?",
"voice": "alloy"
}' \
--output speech.mp3
const axios = require('axios');
const fs = require('fs');
const apiKey = 'YOUR_API_KEY';
const url = 'https://platform.llmprovider.ai/v1/audio/speech';
const data = {
model: 'qwen2-audio-instruct',
input: 'Hello, how are you today?',
voice: 'alloy'
};
const headers = {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json',
'responseType': 'arraybuffer'
};
axios.post(url, data, { headers })
.then(response => {
fs.writeFileSync('speech.mp3', response.data);
console.log('Audio file saved as speech.mp3');
})
.catch(error => {
console.error('Error:', error);
});
import requests
api_key = 'YOUR_API_KEY'
url = 'https://platform.llmprovider.ai/v1/audio/speech'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
data = {
'model': 'qwen2-audio-instruct',
'input': 'Hello, how are you today?',
'voice': 'alloy'
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
with open('speech.mp3', 'wb') as f:
f.write(response.content)
print('Audio file saved as speech.mp3')
else:
print('Error:', response.status_code, response.text)
For any questions or further assistance, please contact us at [email protected].